import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:ball_lion/widgets/picker_local.dart';
import 'package:ball_lion/widgets/base/wqs_button.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';
import 'package:ball_lion/resources/colours.dart';
import '../max_bottom_sheet.dart';

class QsTimePicker extends StatelessWidget {
  const QsTimePicker({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    DateTime time = DateTime.now();
    return MaxBottomSheet(
      onClosing: () {},
      backgroundColor: Colours.white,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      builder: (BuildContext context) => Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          QsText(title, fontSize: 16).paddingSymmetric(vertical: 30),
          SizedBox(
            height: 147,
            child: Localizations.override(
              context: context,
              locale: const Locale("zh", "CN"),
              delegates: const [PickerLocalizations.delegate],
              child: CupertinoDatePicker(
                use24hFormat: true,
                itemExtent: 36,
                mode: CupertinoDatePickerMode.dateAndTime,
                minimumDate: DateTime.now(),
                maximumDate: DateTime(DateTime.now().year, 12, 31, 23, 59, 59),
                maximumYear: DateTime.now().year,
                onDateTimeChanged: (DateTime value) => time = value,
              ),
            ),
          ),
          Padding(
            padding:
                const EdgeInsets.only(top: 30, bottom: 20, left: 16, right: 16),
            child: Row(children: [
              Flexible(
                child: QsButton(
                  width: double.infinity,
                  height: 44,
                  backgroundColor: Colours.greyF2,
                  foregroundColor: Colours.grey66,
                  borderRadius: 8,
                  onPressed: () {
                    navigator?.pop();
                  },
                  text: '取消',
                ),
              ),
              const SizedBox(width: 16),
              Flexible(
                child: QsButton(
                  width: double.infinity,
                  height: 44,
                  backgroundColor: Colours.main,
                  foregroundColor: Colours.white,
                  borderRadius: 8,
                  onPressed: () => navigator?.pop(time),
                  text: '确定',
                ),
              )
            ]),
          ),
        ],
      ),
    );
    ;
  }
}
